<!DOCTYPE html>
<html>
<head>
    <title>插件列表</title>
    <include file='public/head'>
        <style>
            .layui-width-100{width: 100px !important;}
            .layui-legend-size{font-size:14px !important;}
            .layui-nopadding{padding:0 !important;}
            .layui-nomargin{margin: 0 !important;}
            .layui-bottom{
                border-width: 0 0 1px 0;
                border-style: solid;
                border-color: rgb(226, 226, 226);
            }
            .layui-input{height:30px !important; }
            .layui-top-margin{margin: 2px 0;}
            .layui-left-margin{margin-left: 10px;}
            .layui-table-page {padding: 7px 0px 0px;}
        </style>
</head>
<body>
    <!-- layui-tab开始 -->
    <div class="layui-tab " lay-filter="demo-tab">
        <div class="layui-tab-nav" >
            <ul class="layui-tab-title">
                <php> $currentTab = 2 ; </php>
    <li  style="padding: 0;" <?php if( $currentTab== 2 ) echo 'class="layui-this"' ; ?> ><a  style="padding:0 15px;" href="{:cmf_plugin_url('ModuleConfig://PluginList/index')}?name={$data.name}&store_id={$data.store_id}&file_name={$data.file_name}">插件列表</a></li>
    <li style="padding: 0;" <?php if( $currentTab== 3 ) echo 'class="layui-this"' ; ?> ><a style="padding:0 15px;" href="{:cmf_plugin_url('ModuleConfig://TableConfig/index')}?name={$data.name}&store_id={$data.store_id}&file_name={$data.file_name}">模块配置</a></li>
    <li style="padding: 0;" <?php if( $currentTab== 5 ) echo 'class="layui-this"' ; ?> ><a style="padding:0 15px;" href="{:cmf_plugin_url('ModuleConfig://RelevanceConfig/index')}?name={$data.name}&store_id={$data.store_id}&file_name={$data.file_name}">关联配置</a></li>


            </ul>
        </div> 
        <fieldset class="layui-elem-field layui-field-title " style="border-width: 1px;padding-left: 10px;">
            <legend class="layui-legend-size">搜索</legend>
            <form class="layui-form table-bar" action="{:cmf_plugin_url('ModuleConfig://plugin_list/index')}" lay-filter="form-bar" id="search-form">
                <div class="layui-form-item" style="margin-bottom: 0px;">
                    <label>模块名：</label>
                    <div class="layui-inline ">
                        <div class="layui-input-inline" style="width: 100px;">
                            <select name="name_storeid" lay-filter="module_name" lay-search>
                                <foreach name="module_list" item="vo">
                                    <option value="{$vo.name}|{$vo.store_id}" <?php if($vo['name'] == $data['name']){echo 'selected';}?>>{$vo.title}</option>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
                    </div>
                </div>
            </form>
        </fieldset>
        <div class="layui-card-body layui-nopadding " style="margin-top:20px">
                <table  class="layui-table layui-nomargin" >
                    <thead> 
                        <tr>
                            <th>插件名称</th>
                            <th>作者</th>
                            <th>标识</th>
                            <th>说明</th>
                            <th>版本</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody >
                        <volist name="list" id="vo">
                            <tr>
                                <td>{$vo.title}</td>
                                <td>{$vo.author}</td>
                                <td>{$vo.name}</td>
                                <td>{$vo.describe}</td>
                                <td>{$vo.version}</td>
                                <td>
                                    <switch name="vo.status">
                                        <case value="0"><span class="layui-badge">开发中</span></case>
                                        <case value="4"><span class="layui-badge layui-bg-blue">完成</span></case>
                                    </switch>
                                </td>
                                <td type="text/html" id="action_bar" width="100">
                                    <div class="layui-btn-group">
                                        <if condition="$vo.status ==4">
                                            <if condition="$vo.is_install == 'true'">
                                                <button type="button" data-name="{$vo.name}" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs delete-btn" title="卸载"><i class="layui-icon">&#xe640;</i></button>
                                                <else />
                                                <button type="button" data-name="{$vo.name}" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs install-btn" title="安装"><i class="layui-icon">&#xe601;</i></button>
                                            </if>
                                        </if>
                                        <a href="{:cmf_plugin_url('ModuleConfig://help_file/index')}?id={$vo.word}" class="layui-btn layui-btn-primary layui-btn-xs" target="_blank" title="文档"><i class="layui-icon">&#xe705;</i></a>
                                    </div>
                                </td>
                            </tr>
                        </volist>
                    </tbody>
                </table>
                <!-- 分页开始 -->
                <!-- <div class="layui-table-page">
                    <div id="layui-table-page1">
                        <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
                            {$page|default=''}
                        </div>
                    </div>
                </div> -->
                <!-- 分页结束 -->
            </div>
        <!-- 内容结束 -->
    </div>
    <!-- layui-tab结束 -->
    <include file='public/scripts'>
<script >
$(function(){
    var layer = layui.layer
    ,form = layui.form;
    //搜索框
    form.on('select(module_name)', function(obj){
        console.log(obj);
        var module_name = obj.value;
        let url = "{:cmf_plugin_url('ModuleConfig://table_config/getFileName')}?module_name="+module_name;
        $.ajax({
            url:url,
            type:'post',
            success:function(data){
                if ( data.code == 1 ) {
                    var html = '';
                    $.each(data.data,function(k,v){
                        html += '<option value="'+v+'">'+v+'</option>';
                    })
                    $('#file-li').html(html);
                    form.render();
                } 
            },
            error:function(){
                layer.msg( '系统错误' , { time:1200 , icon:2 });
            }
        })
    });
});
</script>
<script >
layui.use('table', function(){
    var table = layui.table;
    //查看文档
    $('.detail-btn').on('click',function(){
        let id = $(this).data('id');
        let url = "{:cmf_plugin_url('ModuleConfig://help_file/index')}?id="+id;
        //当事件为查看详情的时候,open一个页面,内容为data.content
        layer.open({
            type: 2
            ,title: "查看" //不显示标题栏
            ,titleAlign:'c'
            ,closeBtn: false
            ,area: ['800px', '600px']
            ,shade: 0.8
            ,id: 'LAY_article' //设定一个id，防止重复弹出
            ,btn: ['确定']
            ,btnAlign: 'c'
            ,content:url
            ,moveType: 1
        });
    });
    //卸载 
    $('.delete-btn').on('click',function(){
        var  text = "确定要卸载此插件吗？";
        let id = $(this).data('id');
        let plugin_name = $(this).data('name');
        let module_name = "{$data.name}";
        let url = "{:cmf_plugin_url('ModuleConfig://InstallCheck/uninstall')}";
        layer.confirm(text, {icon: 3, title:'提示', btn: ['卸载','取消']}, function(index,layero){
            $.ajax({
                url:url,
                data:{
                    plugin_name:plugin_name,
                    module_name:module_name,
                    id:id
                },
                success:function(data){
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:1,time:1500},function(){
                            window.location.reload();
                        });
                    } else {
                        layer.msg(data.msg,{icon:2,time:1500});
                    }
                },
                error:function(){
                    layer.msg('系统错误',{icon:2,time:1500});
                }
            })
        },function(index){
            // alert('取消');
        });
    });
    //安装 
    $('.install-btn').on('click',function(){
        var text = "确定要安装此插件吗？";
        let id = $(this).data('id');
        let plugin_name = $(this).data('name');
        let module_name = "{$data.name}";
        let url = "{:cmf_plugin_url('ModuleConfig://plugin_list/install')}?plugin_name="+plugin_name+"&module_name="+module_name+"&id="+id;
        layer.confirm(text, {icon: 3, title:'提示', btn: ['安装','取消']}, function(index,layero){
            install(url);
        },function(index){
            // alert('取消');
        });
    });
    var install = function(url){
        layer.open({
            type: 2,
            title: false,
            shade: 0.1,
            skin: 'layui-layer-fast', //样式类名
            area: ['500px', '355px'],
            btn:['关闭'],
            btnAlign: 'c',
            content:url,
            yes: function (index, layero) {
                layer.close(index);
                layer.closeAll('dialog');
                window.location.reload();
                // var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            },
            btn2:function(index, layero){
            }
        });
    };
});
</script>
</body>
</html>